<template>
  <div>
    <el-row>
      <el-col :span="8" :offset="8">
        <div>
          <el-input placeholder="请输入名称" v-model="search" class="search">
            <el-button @click.capture="searchFn(search)" slot="append">
              <i class="el-icon-search searchIcon" ></i>
            </el-button>
          </el-input>
          
        </div>
        <div class="label">
            <span
              v-for="item2 in label"
              :key="item2"
              :class="colorArr[parseInt(Math.random() * 4)]"
              @click="searchFn(item2)"
              >{{ item2 }}</span
            >
          </div>
      </el-col>
    </el-row>

    <div class="fenlei">
      <el-row>
        <el-col :span="2" class="tit">
          <el-dropdown trigger="click" @command="selections">
            <span class="el-dropdown-link">
              {{ option }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="按部位">按部位</el-dropdown-item>
              <el-dropdown-item command="按科室">按科室</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
        <el-col :span="22">
          <span
            v-for="item in cla"
            :key="item.id"
            @click="searchFn(item.name,2,search,item.id)"
            :class="friInd == item.id ? 'yiji yijiAc' : 'yiji'"
            ><img :src="item.iconImg" alt="" />{{ item.name }}</span
          >
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  name: "searchandlist",
  data() {
    return {
      staCla: {
        //两种状态的分类
      },
      option: "按部位",
      friInd: 0, //选中的一级分类图标
      state: 1,
      search: "",
      label: ["腹部", "头部", "高血压"],
      colorArr: ["bi-bor", "yi-bor", "ri-bor", "gi-bor"],
    };
  },
  computed: {
    cla() {
      //一级分类
      return this.state == 1 ? this.staCla.pos : this.staCla.dep;
    },
  },
  methods: {
    selections(command) {
      this.option = command;
      if (command === "按科室") {
        this.state = 2;
      } else {
        this.state = 1;
      }
    },
    searchFn(con,type,sea,id){//tag,类型，搜索框内容，分类id
      this.$emit('search',con,type,sea,id)
      this.search=""
    }
  },
  created(){
     //获取分类树classifyTree
    this.staCla.pos=this.$getStorage('classifyTree').partTree
    this.staCla.dep=this.$getStorage('classifyTree').departmentTree
  }
};
</script>

<style lang="less" scoped>
.fenlei {
  margin: 0 auto;
  background-color: #c6cddb;
  width: 1200px;
  padding: 20px;
  box-sizing: border-box;
  border-radius: 10px;
  text-align: left;
  .tit {
    line-height: 40px;
    margin: 10px 0;
    text-align: right;
  }
  .yiji {
    user-select: none;
    text-align: left;
    display: inline-block;
    line-height: 40px;
    font-size: 18px;
    margin: 10px 10px;
    padding: 0 10px;
    border-radius: 5px;
    cursor: pointer;
    img {
      height: 35px;
      vertical-align: middle;
      margin-right: 5px;
    }
  }
  .yijiAc {
    background-color: #9ba5bb;
    color: white;
  }
}

.el-dropdown-link {
  cursor: pointer;
  color: black;
  font-size: 20px;
}
.el-icon-arrow-down {
  font-size: 16px;
}

.el-dropdown-menu__item {
  font-size: 16px;
}

::v-deep .search {
  margin: 50px 0 10px;
  height: 50px;
  border: 1px solid #312a6d;
  border-radius: 25px;
  overflow: hidden;
  & input {
    height: 50px !important;
    font-size: 18px;
    color: black;
    border-radius: 25px 0 0 25px;
    border: none;
  }
  & input::placeholder {
    font-size: 18px;
    color: #7a7a79;
    line-height: 50px;
  }
}

.searchIcon {
  font-size: 25px;
}

::v-deep .el-input-group__append {
  width: 45px;
  background-color: #312a6d;
  color: white;
  border: none;
}
.label {
margin-bottom: 30px;
text-align: left;
  span {
  background-color: white;
  color: #9ba5bb;
  font-size: 8px;
  border-radius: 5px;
  padding: 4px;
  margin: 8px 5px;
  text-align: left;
  
}
} 
</style>

